package com.jim.healio.agents.impl;

import com.jim.healio.agents.Agent;
import com.jim.healio.dto.Message;
import com.jim.healio.tools.UserTool;
import com.jim.healio.utils.PromptUtil;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.converter.BeanOutputConverter;
import org.springframework.stereotype.Component;

@Component
public class TestAgent{

    private final ChatClient chatClient;

    BeanOutputConverter<Message> beanOutputConverter;

    private final String outputFormat;

    public TestAgent(ChatClient.Builder chatClientBuilder) {
       chatClient = chatClientBuilder
               .defaultSystem(PromptUtil.getArchivistSystemPrompt())
//               .defaultTools()
               .build();
       beanOutputConverter = new BeanOutputConverter<>(Message.class);
       outputFormat = beanOutputConverter.getFormat();
        System.out.println(outputFormat);
    }

    public Message chat(String message) {

        String content = chatClient.prompt(message).tools(new UserTool()).call().content();
        System.out.println(content);

        assert content != null;
        return beanOutputConverter.convert(content);

    }

}